package com.lagou.edu.utils;

import com.lagou.edu.exception.InitException;

import java.sql.Connection;
import java.sql.SQLException;

public class ConnectionUtils {

    private final ThreadLocal<Connection> CONNECTION_HOLDER = ThreadLocal.withInitial(() -> {
        try {
            return DruidUtils.getInstance().getConnection();
        } catch (SQLException e) {
            throw new InitException(e);
        }
    });

    public Connection getConnection() {
        return CONNECTION_HOLDER.get();
    }

}
